package com.vision.sales.cl.ui.component;

import com.google.gwt.core.client.GWT;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.text.shared.SafeHtmlRenderer;
import com.google.gwt.uibinder.client.UiConstructor;
import com.sencha.gxt.core.client.XTemplates;
import com.sencha.gxt.data.shared.LabelProvider;
import com.sencha.gxt.data.shared.ListStore;
import com.sencha.gxt.widget.core.client.form.ComboBox;
import com.vision.sales.cl.data.SalesInvoiceProperties;
import com.vision.sales.cm.db.data.SalesInvoice;

/**
 * 
 * @author Mark
 *
 */
public class SalesInvoiceComboBox extends ComboBox<SalesInvoice> {
	
	public static interface Templates extends XTemplates {
		
		public static final Templates INSTANCE = GWT.create(Templates.class);
		 
	    @XTemplate("<div><b>{invoiceNo}</b>&nbsp;&nbsp;&nbsp;&nbsp;Date: {date}<br/>Gross: {grossSales}&nbsp;&nbsp;&nbsp;&nbsp;Balance: {balance}</div>")
	    SafeHtml invoice(String date, String invoiceNo, String grossSales, String balance);
	 
	}
	
	private static final LabelProvider<SalesInvoice> LABEL_PROVIDER = new LabelProvider<SalesInvoice>() {
		@Override
		public String getLabel(SalesInvoice item) {
			return item.getGroupAndNo();
		}
	};
	
	@UiConstructor
	public SalesInvoiceComboBox() {
		super(new ListStore<SalesInvoice>(SalesInvoiceProperties.INSTANCE.key()), LABEL_PROVIDER);
	}
	
	public SalesInvoiceComboBox(SafeHtmlRenderer<SalesInvoice> renderer) {
		this(new ListStore<SalesInvoice>(SalesInvoiceProperties.INSTANCE.key()), renderer);
	}

	public SalesInvoiceComboBox(ListStore<SalesInvoice> store, SafeHtmlRenderer<SalesInvoice> renderer) {
		super(store, LABEL_PROVIDER, renderer);
	}
	
}
